var Color = net.brehaut.Color;
class LwMap {
  /**
   * 全局对象：
   * this.map 真实的map对象
   * this.mapBox map中存放覆盖物的容器
   */

  /**xxx
   * 构造方法
   * container: DOM ID
   * center: 中心点 eg: [116.404, 39.915] 北京
   * zoom: 缩放级别 {Number | Array(3)[zoom, minZoom, maxZoom]}
   */
  constructor(container, center = [116.404, 39.915], zoom = [11, 3, 18], extraConfig = {}) {
    var isDev = location.href.includes('localhost') || location.hostname.includes("127"); // 内网
    var layers = '';
    var MAPHOST = isDev ? 'http://t{s}.tianditu.gov.cn' : ' http://2.18.220.192:8080';
    layers = [
      // MAPHOST + '/DataServer?T=img_c&tk=c27c613115979d179e2794dcb248c29d&x={x}&y={y}&l={z}',
      MAPHOST + '/DataServer?T=img_c&tk=3f4a97ee5cf6315de1ad7fb4ac94cd75&x={x}&y={y}&l={z}',
      MAPHOST + '/DataServer?T=cva_c&tk=3f4a97ee5cf6315de1ad7fb4ac94cd75&x={x}&y={y}&l={z}'
    ].map(n => {
      return L.tileLayer.colorizr(n, {
        crs: L.CRS.EPSG4326,
        tileSize: 256,
        minZoom: $Config.MAP_LAYER_MINZOOM || 3,
        maxZoom: $Config.MAP_LAYER_MAXZOOM || 18,
        subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
        colorize: function (pixel) {
          pixel.r += 13;
          pixel.g += 17;
          pixel.b += 90;
          return pixel;
        }
      });
    });

    L.CRS.CustomEPSG4326 = L.extend({}, L.CRS.Earth, {
      code: 'EPSG:4326',
      projection: L.CRS.TianDiTu_WGS84.projection,
      transformation: new L.Transformation(1 / 180, 1, -1 / 180, 0.5),
      scale: function (zoom) {
        return 256 * Math.pow(2, zoom - 1);
      }
    });
    var p84 = coordtransform.gcj02towgs84(center[0], center[1]);
    var map = new L.map(container, {
      crs: L.CRS.CustomEPSG4326,
      preferCanvas: true,
      zoom: zoom[0],
      minZoom: zoom[1],
      maxZoom: zoom[2],
      zoomControl: false,
      layers: layers,
      // layers: [],
      center: [p84[1], p84[0]]
    });
    var vm = this;
    vm.map = map;
    vm.mapBox = {}; // 所有地图元素的数组
    vm.obj3DBoundBox = [];
    vm.clusterMarkers = {};
    vm.loadPromise = new Promise((resolve) => {
      resolve();
    });
  }
  addOuterFeature(){}
  showHeatOverLay(data) {
    var vm = this;
    if (this.heatmapOverlay) {
      this.map.removeLayer(this.heatmapOverlay);
    }
    if (!data) {
      var center = this.map.getCenter();
      data = new Array(10000).fill(1).map(() => {
        return { count: Math.random() * 300, lng: center.lng + (0.5 - Math.random()) / 2, lat: center.lat + (0.5 - Math.random()) / 3 };
      });
    }
    data.forEach(n => {
      var p84 = coordtransform.gcj02towgs84(n.lng, n.lat);
      n.lng = p84[0];
      n.lat = p84[1];
    });
    var heatmapOverlay = new L.heatLayer(data.map(n => [n.lat, n.lng, n.count]), {
      radius: 15,
      minOpacity: 0.5,
      max: _.max(data.map(n => n.count))
    }).addTo(this.map);
    heatmapOverlay.hide = function () {
      this.removeFrom(vm.map);
    }
    heatmapOverlay.show = function () {
      this.addTo(vm.map);
    }
    this.heatmapOverlay = heatmapOverlay;
    return heatmapOverlay;
  }
  addOuterPolygon() {

  }
  addOuterPolygon1(boundArray) {
    var outer = [
      new T.LngLat(-360, 90),
      new T.LngLat(-360, -90),
      new T.LngLat(360, -90),
      new T.LngLat(360, 90)
    ];
    var pathArray = [
      outer
    ];
    if (!(boundArray instanceof Array)) {
      boundArray = [boundArray];
    }
    boundArray.forEach(feature => {
      var cps = feature.geometry.coordinates.length == 1 ? feature.geometry.coordinates[0] : feature.geometry.coordinates;
      pathArray.push(cps.map((lnglat) => {
        var p84 = coordtransform.gcj02towgs84(lnglat[0], lnglat[1]);
        return new T.LngLat(p84[0], p84[1]);
      }));
    });
    var mesh = new T.Polygon(pathArray, {
      color: 'cyan',
      weight: 0,
      opacity: 1,
      fillColor: '#0a3473',
      fillOpacity: 1
    });
    this.__addObject('outerPolygon', mesh);
  }

  // 聚合点
  addMarkerCluster (groupId, typeId, data, url, size, offset, onclick) {
    !groupId && (groupId = typeId);
    var clusterMarker = this.clusterMarkers['Cluster' + groupId];
    if (!clusterMarker) {
      clusterMarker = L.markerClusterGroup({
        spiderfyOnMaxZoom: true,
        showCoverageOnHover: true,
        iconCreateFunction: function(cluster) {
          var markers = cluster.getAllChildMarkers();
          var n =  markers.length;
          var css='_normal';
          var pt= L.point(36, 36);
          if(n >= 100) {
            css='_big';
            pt = L.point(48, 48);
          }
          return L.divIcon({ html: n, className: 'clusterAll ' + css + ' _' + groupId, iconSize: pt });
        }
      });
      this.clusterMarkers['Cluster' + groupId] = clusterMarker;
      this.__addObject('Cluster' + groupId, clusterMarker);
    }
    var icon = new L.icon({
      iconUrl: url,
      iconSize: size,
      iconAnchor: offset,
    });
    data.forEach((item) => {
      var p84 = coordtransform.gcj02towgs84(item.lng, item.lat);
      var marker = new L.marker(new L.latLng(p84[1], p84[0]), {
        icon: icon
      });
      marker.clz = typeId;
      onclick && marker.on('click', (t) => {
        // 使用实际点击的经纬度打开
        var cp84 = coordtransform.wgs84togcj02(t.latlng.lng, t.latlng.lat);
        onclick($.extend(item, {lng: cp84[0], lat: cp84[1]}));
      });
      clusterMarker.addLayer(marker);
    });
    // this.map.addLayer(clusterMarker);
    // this.__addObject('Cluster' + groupId, typeId, clusterMarker);
  }

  removeClusterMarker (groupId, typeId) {
    !groupId && (groupId = typeId);
    var clusterMarker = this.clusterMarkers['Cluster' + groupId];
    if (clusterMarker) {
      var children = clusterMarker.getLayers();
      var targetChilds = children.filter(n => n.clz == typeId);
      clusterMarker.removeLayers(targetChilds);
    }
  }
  // 需要实现的方法
  /**
   * 地图移动
   * 参数 二维坐标
   */
  panTo(point) {
    var p84 = coordtransform.gcj02towgs84(point[0], point[1]);
    this.map.panTo(new L.latLng(p84[1], p84[0]));
  }

  addControlBar(offset = [0, 0], zoom = 1) {}

  /**
   * 设置地图缩放级别
   * 参数 zoom
   */
  setZoom(zoom) {
    this.map.setZoom(zoom);
  }

  getZoom() {
    return this.map.getZoom();
  }

  /**
   * 设置地图缩放级别
   */
  setCenterAndZoom(point, zoom) {
    var p84 = coordtransform.gcj02towgs84(point[0], point[1]);
    this.map.setView(new L.latLng(p84[1], p84[0]), zoom);
  }

  /**
   * 增加标注物
   * 参数 id，url, 坐标点, 图片偏移，点击事件
   */
  addMarker(id, url, point, size, offset, onclick, params, labelName) {
    var p84 = coordtransform.gcj02towgs84(point[0], point[1]);
    var icon = new L.icon({
      iconUrl: url,
      iconSize: size,
      iconAnchor: offset,
    });
    var marker = new L.marker(new L.latLng(p84[1], p84[0]), {
      icon: icon
    });
    onclick && marker.on('click', onclick);
    marker = _.extend(marker, params);
    if (labelName) {
      var text = L.marker([p84[1], p84[0]], {
        icon: L.divIcon({
          html: `<div style="font-size:12px;text-align:center;border-radius:5px;color:#ffffff;line-height:20px!important">${labelName}</div>`,
          className: 'lf-marker-label'
        })
      });
      this.__addObject('MarkerLabel' + id, text);
      marker.linkObject = [text];
    }
    this.__addObject(id, marker);
    marker.getElement().classList.add(id);
  }
  setAnimation (element, className, time = 2000) {
    var ele = element.getElement();
    if (ele) {
      ele.classList.add('CurrentEvent');
      setTimeout(() => {
        ele && ele.classList.remove('CurrentEvent');
      }, time)
    }
  }
  removeAnimation() {}

  addBreatheMarker(id, url, point, size, offset, defaultShow, onclick, params, labelName) {
    var vm = this;
    var p84 = coordtransform.gcj02towgs84(point[0], point[1]);
    var icon = new L.icon({
      iconUrl: url,
      iconSize: size,
      iconAnchor: offset,
    });
    var marker = new L.marker(new L.latLng(p84[1], p84[0]), {
      icon: icon
    });
    marker.show = function () {
      this.setOpacity(1);
    };
    marker.hide = function () {
      this.setOpacity(0);
    };
    onclick && marker.on('click', onclick);
    marker = _.extend(marker, params);
    if (!defaultShow) {
      marker.hide();
    }
    vm.__addObject(id, marker);
  }

  // 移除物体 参数 name : 需要删除物体的ID
  removeObject(name) {
    var obj = this.mapBox[name];
    if (obj) {
      obj.linkObject && obj.linkObject.forEach(lo => {
        this.map.removeLayer(lo);
      });
      this.map.removeLayer(obj);
    }
    delete this.mapBox[name];
  }

  add3DBoundaryByFeatureV2(feature, rgb, opacity = 0.7, height = 2000, zooms = '', onclick = '', type = '') {
    var vm = this;
    var bounds = [];
    feature.geometry.coordinates[0].forEach(function (i) {
      var p84 = coordtransform.gcj02towgs84(i[0], i[1]);
      bounds.push([p84[1], p84[0]]);
    });
    var color = this.__getRandomRgbColor();
    color = `rgb(${color[0]},${color[1]},${color[2]})`;
    var mesh = L.polygon(bounds, {
      color: $Config.MAP_BORDER_COLOR || 'cyan',
      weight: 4,
      opacity: 0.8,
      fillColor: color,
      fillOpacity: opacity
    });
    var cp84 = coordtransform.gcj02towgs84(feature.properties.cp[0], feature.properties.cp[1]);
    var text = L.marker([cp84[1], cp84[0]], {
      icon: L.divIcon({
        html: `<div style="background-color:rgba(255, 88, 219, 0.52);font-size:12px;text-align:center;border-radius:5px;color:#ffffff;line-height:20px!important">${feature.properties.name}</div>`,
        className: 'polygon-marker'
      })
    });
    mesh.zooms = zooms;
    mesh.type = type || feature.type;
    mesh.linkObject = [text];
    mesh.lwcolor = color;
    if (onclick) {
      mesh.addEventListener($Config.prismClick || "click", onclick);
    }
    mesh.addEventListener("mouseover", function () {
      mesh.setStyle({
        color: 'yellow',
        weight: 6,
        fillOpacity: 0
      });
    });
    mesh.addEventListener("mouseout", function () {
      var o = (18 - vm.map.getZoom()) * 0.1;
      mesh.setStyle({
        color: $Config.MAP_BORDER_COLOR || 'cyan',
        weight: 4,
        fillOpacity: o > 0 ? o : 0.1
      });
    });
    this.obj3DBoundBox.push(mesh);
    this.__addObject(feature.id + '_mesh', mesh);
    this.__addObject(feature.id + '_text', text);
  }

  /**
   * 清除类型为type的所有网格
   */
  removeFeature(type) {
    var vm = this;
    vm.obj3DBoundBox.forEach(function (obj) {
      // if (obj.type == type) {
      if (obj.linkObject) {
        obj.linkObject.forEach(o => {
          // vm.object3Dlayer.remove(o);
          vm.map.removeLayer(o);
        });
      }
      vm.map.removeLayer(obj);
      // }
    });
    vm.obj3DBoundBox = [];
    // _.remove(vm.obj3DBoundBox, (n) => { return n.type == type; });
  }

  /**
   * 设置轨迹路线
   * 轨迹数组 pathArr: [[a,b], [a,b]],
   * 图片路径 imgPath: url,
   * 图片大小 imgSize: [num,num],
   * 图片锚点 imgAncher: [num,num],
   * 图片标签名称 lableName: 'abc',
   * 图片标签偏移 labelOffset: [num,num],
   * 图片与锚点的位置 position: /BL、BM、BR、ML、MR、TL、TM、TR分别代表左下角、底部中央、右下角、左侧中央、右侧中央、左上角、顶部中央、右上角,
   * 轨迹线 lineColor: '#aaaa',
   * 轨迹线宽 lineWeight : num,
   * 点移动速度 speed : num,
   * return 点操控办法:start, pause, resume, stop, setSpeed, setPassLine
   */
  addMarkerAndPath(pathArr, imgPath, imgSize, imgAncher, lableName = '', labelOffset = [-35, 0], position = 'BM', lineColor = '#1104c7', lineWeight = 10, speed = 1000) {
    var vm = this;
    var marker = this.__buildElasticMarker(pathArr[0][0], imgPath, imgSize, imgAncher, lableName, labelOffset, position);
    !marker.linkObject && (marker.linkObject = []);
    // 删掉老的
    this.removeMarkerAndPath();
    var points = [];
    pathArr.forEach((apath) => {
      apath.forEach(point => {
        var p84 = coordtransform.gcj02towgs84(point[0], point[1]);
        points.push([p84[1], p84[0]]);
      });
    });

    var line = L.polyline(points, {color: 'red'}).addTo(this.map);
    // var line = new T.Polyline(points);
    // this.map.addOverLay(line);
    marker.linkObject.push(line);
    this.__addObject('pathAndMarker', marker);
    return {
      marker: marker,
      map: this.map,
      status: 0, // 0 停止   1: 在跑  2: 暂停,
      speed: speed,
      pathArr: points,
      afterMoveAlongEnd: function () {
        console.log('跑完第' + ++this.pathIndex + '段');
        var nextPath = this.path[this.pathIndex];
        if (nextPath) {
          this.run(this.speed, this.pathIndex);
        }
      },
      afterMoveTo: function () {
        this.run(this.speed);
      },
      init: function () {
        this.pathArr = vm.__getDelicatePoints(points);
        this.pointIndex = [0, 0];
      },
      run: function (v) {
        if (v) {
          this.speed = 100000 / v;
          this.status = 1;
        }
        var nextPointIndex = this.pointIndex[0] + 1;
        if (this.pathArr[nextPointIndex]) {
          this.pointIndex = [nextPointIndex, 0];
          var nextPoint = this.pathArr[nextPointIndex];
          if (this.status == 1) {
            setTimeout(() => {
              this.marker.setLatLng(nextPoint);
              this.run();
            }, this.speed);
          }
        } else {
          // 结束了
          this.pointIndex = [0, 0];
          this.status = 0;
        }
      },
      setSpeed: function (speed) {
        this.speed = 100000 / speed;
      },
      /**
       * 设置点暂停
       */
      pause: function () {
        if (this.status == 2) {
          return;
        }
        this.status = 2;
      },
      changeStep: function (offset) {
        offset *= 2;
        var status = this.status;
        if (this.status != 0) {
          var pointIndex = this.pointIndex[0] + offset;
          var point = this.pathArr[pointIndex];
          if (!point) {
            pointIndex = offset > 0 ? this.pathArr.length - 1 : 1;
            point = this.pathArr[pointIndex];
          }
          this.pointIndex[0] = pointIndex;
          if (status == 2) {
            this.marker.setLatLng(point);
          }
        }
      },
      /**
       * 设置点继续移动
       */
      resume: function () {
        if (this.status == 1) {
          return;
        }
        if (this.status == 2) {
          this.status = 1;
          this.run();
        }
      },
      /**
       * 设置点停止
       */
      stop: function () {
        if (this.status == 0) {
          return;
        }
        this.status = 0;
        this.pointIndex = [0, 0];
      },
      /**
       * 设置已经行驶的路线
       * 已行驶路线颜色 lineColor
       * 已行驶路线透明度 lineopacity
       * 已行驶路线线宽 lineWeight
       * 已行驶路线直线样式 lineStyle
       */
      setPassLine: function (lineColor = '#AF5', lineopacity = 1, lineWeight = 6, lineStyle = 'solid') {
        var passedPolyline = new T.Polyline({
          map: this.map,
          strokeColor: lineColor,
          strokeOpacity: lineopacity,
          strokeWeight: lineWeight,
          strokeStyle: lineStyle
        });
        this.marker.on('moving', function (e) {
          passedPolyline.setPath(e.passedPath);
        });
      }
    };
  }
  __getDelicatePoints(points, delicate = 0.01) {
    var result = [];
    // x1, x2, x3, x4, x5, x6
    // o
    for (let i = 0; i < points.length - 1; i++) {
      result.push(points[i]);
      let lng0 = points[i][1];
      let lat0 = points[i][0];
      let lng1 = points[i + 1][1];
      let lat1 = points[i + 1][0];
      var distance = (lng0 - lng1) ** 2 + (lat0 - lat1) ** 2;
      var dx = Math.round(distance / 2e-8); // 要切割dx段  o     1    1    o
      if (dx > 1) {
        dx > 100 && (dx = 100);
        var dltlng = (lng1 - lng0) / dx;
        var dltlat = (lat1 - lat0) / dx;
        for (let j = 1; j < dx; j++) {
          result.push([lat0 + j * dltlat, lng0 + j * dltlng]);
        }
      }
    }
    if (points.length > 1) {
      // 把最后一个点补进去
      result.push(points[points.length - 1]);
    }
    return result;
  }

  addMarkerAndPathV2(pathArr, imgPath, imgSize, imgAncher, lableName = '', labelOffset = [-35, 0], position = 'BM', lineColor = '#1104c7', lineWeight = 10, speed = 1000) {
    var vm = this;
    var marker = this.__buildElasticMarker(pathArr[0], imgPath, imgSize, imgAncher, lableName, labelOffset, position);
    !marker.linkObject && (marker.linkObject = []);
    // 删掉老的
    this.removeMarkerAndPath();
    var points = [];
    pathArr.forEach(point => {
      var p84 = coordtransform.gcj02towgs84(point[0], point[1]);
      points.push([p84[1], p84[0]]);
    });
    var line = new L.polyline(points, {color: 'red'}).addTo(this.map);
    marker.linkObject.push(line);
    this.__addObject('pathAndMarker', marker);

    return {
      map: vm.map,
      marker,
      speed: speed,
      historyArr: [points[0]],
      pathArr: points,
      pointIndex: 0,
      line,
      afterMove: function (foo) {
        this.afterMoveCallback = foo;
      },
      start: function (speed) {
        if (speed) {
          this.speed = speed;
        }
        if (this.pointIndex == 0) {
          this.pointIndex = 0;
          this.map.centerAndZoom(this.pathArr[0], 18);
        }
        var nextPoint = this.pathArr[this.pointIndex + 1];
        if (nextPoint) {
          this.pointIndex += 1;
          var vm = this;
          setTimeout(() => {
            console.log('跑到' + this.pointIndex);
            vm.marker.setLatLng(nextPoint);
            vm.historyArr.push(nextPoint);
            vm.line.setLatLngs(vm.historyArr);
            vm.start(); // 跑完继续跑
          }, this.speed);
        } else {
          console.log(this.pointIndex + '再获取');
          this.afterMoveCallback();
        }
      },
      addPath: function (arr) {
        arr.forEach(point => {
          var p84 = coordtransform.gcj02towgs84(point[0], point[1]);
          this.pathArr.push([p84[1], p84[0]]);
        });
        this.start();
      }
    };
  }

  // 移除
  removeMarkerAndPath() {
    var oldMarker = this.mapBox.pathAndMarker;
    if (oldMarker) {
      // oldMarker.stopMove();
      var linkObjs = oldMarker.linkObject;
      oldMarker.status = 0;
      if (linkObjs) {
        var map = this.map;
        linkObjs.forEach((n) => {
          map.removeLayer(n);
        });
        map.removeLayer(oldMarker);
      }
    }
  }

  getRandomPoint(pathArr) {
    var lngArr = pathArr.map((n) => n[0]);
    var latArr = pathArr.map((n) => n[1]);
    var maxX = _.max(lngArr);
    var minX = _.min(lngArr);
    var maxY = _.max(latArr);
    var minY = _.min(latArr);
    let result = [];
    while (result.length != 50) {
      let lng = minX + (maxX - minX) * Math.random();
      let lat = minY + (maxY - minY) * Math.random();
      let isPointInRing = T.GeometryUtil.isPointInRing([lng, lat], pathArr);
      if (isPointInRing) {
        result.push([lng, lat]);
      }
    }
    return result;
  }

  /**
   * 清除类型为type的所有网格
   * 删除的3D物体
   */
  removeObjByTypename(type) {
    var vm = this;
    vm.obj3DBoundBox.forEach(function (obj) {
      if (obj.type == type) {
        if (obj.linkObject) {
          obj.linkObject.forEach(o => {
            vm.map.removeLayer(o);
            vm.object3Dlayer.remove(o);
          });
        }
        vm.object3Dlayer.remove(obj);
      }
    });
    _.remove(vm.obj3DBoundBox, (n) => {
      return n.type == type;
    });
  }

  /**
   * 清除地图图标
   */
  clearActivities(foo) {
    var vm = this;
    !foo && (foo = (n) => n.lwType == 'activity' || (n.lwType && n.lwType.includes('Marker')));
    if (foo instanceof Function) {
      var keys = Object.keys(vm.mapBox);
      keys.forEach((key) => {
        let obj = vm.mapBox[key];
        if (foo(obj)) {
          vm.removeObject(key);
        }
      });
    }
  }

  showInfoWindow(content, position, anchor = 'bottom-center') {
    if (this.infoWindow) {
      this.infoWindow.remove();
    }
    if (!content) return;
    var p84 = coordtransform.gcj02towgs84(position[0], position[1]);
    var infoWin = new L.popup();
    infoWin.setLatLng(new L.latLng(p84[1], p84[0]));
    infoWin.setContent(content);
    infoWin.openOn(this.map);
    this.infoWindow = infoWin;

  }

  closeInfoWindow() {
    this.infoWindow && this.infoWindow.closeInfoWindow();
  }

  setRotationAndPitch(rotation, pitch) {}

  getRotationAndPitch() {}

  // 私有方法
  __addObject(id, marker) {
    var obj = this.mapBox[id];
    if (obj) {
      // 已经有了
      var linkObjs = obj.linkObject;
      if (linkObjs) {
        var map = this.map;
        linkObjs.forEach((n) => {
          map.removeLayer(n);
        });
      }
      this.map.removeLayer(obj);
    }
    marker.addTo(this.map);
    this.mapBox[id] = marker;
  }
  __getRandomRgbColor() {
    return new Array(3).fill(255).map((o) => {
      return o * Math.random();
    });
  }

  openDrawTools(type = 'polygon') {
    if (!this.drawControl) {
      var editableLayers = new L.FeatureGroup();
      this.editableLayers = editableLayers;
      this.map.addLayer(editableLayers);
      L.drawLocal.draw.handlers.polygon.tooltip = {
        start: "点击开始描绘多边形",
        cont: "继续描绘",
        end: "点击第一个坐标点完成图形"
      };
      var options = {
        position: 'topright',
        draw: {
          polyline: false,
          polygon: {},
          circle: true,
          rectangle: true,
          marker: false,
          circlemarker: false
        },
        edit: {
          featureGroup: editableLayers,
          remove: true
        }
      };
      var drawControl = new L.Control.Draw(options);
      this.drawControl = drawControl;
      this.map.addControl(drawControl);
      this.map.on(L.Draw.Event.CREATED, function (e) {
        var layer = e.layer;
        editableLayers.addLayer(layer);
      });
    }
    setTimeout(() => {
      $('.leaflet-draw-draw-' + type + ' span').trigger("click");
    }, 100);
  }
  cancelDraw () {
    $('a[title="Cancel drawing"]')[0] && $('a[title="Cancel drawing"]')[0].click()
    if (this.editableLayers) {
      this.editableLayers.clearLayers();
    }
  }


  __buildElasticMarker(position, imgPath, imgSize, imgAncher, lableName = '', labelOffset = [-35, 0], labelPosition = 'BM') {
    var p84 = coordtransform.gcj02towgs84(position[0], position[1]);
    var icon = new L.icon({
      iconUrl: imgPath,
      iconSize: imgSize,
      iconAnchor: imgAncher,
    });
    var marker = new L.marker(new L.latLng(p84[1], p84[0]), {
      icon: icon
    });
    onclick && marker.on('click', onclick);
    if (lableName) {
      var text = L.marker([p84[1], p84[0]], {
        icon: L.divIcon({
          html: `<div style="font-size:12px;text-align:center;border-radius:5px;color:#ffffff;line-height:20px!important">${lableName}</div>`,
          className: 'lf-marker-label'
        })
      });
      this.__addObject('GuijiLabel', text);
      marker.linkObject = [text];
    }
    return marker;
  }
}
window.LwMap = LwMap;
